#include "Avalon/SignalHandling/GroupConnection.hpp"

using namespace Avalon;
using namespace Avalon::SignalHandling;
using namespace boost;
using namespace boost::signals2;
using namespace std;

GroupConnection::GroupConnection() {}

GroupConnection::GroupConnection(const vector<connection>& connections)
    : m_connections(connections) {}

GroupConnection::GroupConnection(const connection& connection) {
  m_connections.push_back(connection);
}

GroupConnection::GroupConnection(const connection& connection0,
    const connection& connection1) {
  m_connections.push_back(connection0);
  m_connections.push_back(connection1);
}

GroupConnection::GroupConnection(const connection& connection0,
    const connection& connection1, const connection& connection2) {
  m_connections.push_back(connection0);
  m_connections.push_back(connection1);
  m_connections.push_back(connection2);
}

GroupConnection::GroupConnection(const connection& connection0,
    const connection& connection1, const connection& connection2,
    const connection& connection3) {
  m_connections.push_back(connection0);
  m_connections.push_back(connection1);
  m_connections.push_back(connection2);
  m_connections.push_back(connection3);
}

GroupConnection& GroupConnection::operator =(const GroupConnection& rhs) {
  if(this == &rhs) {
    return *this;
  }
  m_connections = rhs.m_connections;
  return *this;
}

const vector<connection>& GroupConnection::GetConnections() const {
  return m_connections;
}

void GroupConnection::Swap(GroupConnection& group) {
  std::swap(m_connections, group.m_connections);
}

void GroupConnection::Disconnect() {
  for(vector<connection>::const_iterator i = m_connections.begin();
      i != m_connections.end(); ++i) {
    i->disconnect();
  }
}

void Avalon::SignalHandling::swap(GroupConnection& a, GroupConnection& b) {
  a.Swap(b);
}

template<> void std::swap(GroupConnection& a, GroupConnection& b) {
  a.Swap(b);
}
